package com.fetch.spider;

import org.tinygroup.htmlparser.node.HtmlNode;
import org.tinygroup.parser.filter.QuickNameFilter;
import org.tinygroup.tinyspider.Spider;
import org.tinygroup.tinyspider.Watcher;
import org.tinygroup.tinyspider.impl.SpiderImpl;
import org.tinygroup.tinyspider.impl.WatcherImpl;

public class FetchSpider {
        
//        static String host = "http://tp.ananlu.com/meituisiwa/20140615/6905.html";
//        static String baseUrl = "http://tp.ananlu.com";
        static String host = "http://www.leg188.com/theme/1278/1.html";
        static String baseUrl = "http://www.leg188.com";
        
        public static void download() throws Exception {
            Watcher watcher = new WatcherImpl();
            Spider spider = new SpiderImpl();
            watcher.addProcessor(new ImgProcessor2());
            QuickNameFilter<HtmlNode> nodeFilter = new QuickNameFilter<HtmlNode>();

            nodeFilter.setNodeName("div");
//            nodeFilter.setIncludeAttribute("class", "n_bd");
            nodeFilter.setIncludeAttribute("class", "Createcontenr");
            
            watcher.setNodeFilter(nodeFilter);
            spider.addWatcher(watcher);
            spider.processUrl(host);

        }

        public static void main(String[] args) {
            Watcher watcher = new WatcherImpl();
            Spider spider = new SpiderImpl();
            watcher.addProcessor(new ImgProcessor2());
            QuickNameFilter<HtmlNode> nodeFilter = new QuickNameFilter<HtmlNode>();

            nodeFilter.setNodeName("div");
//            nodeFilter.setIncludeAttribute("class", "n_bd");
            nodeFilter.setIncludeAttribute("class", "Createcontenr");

            watcher.setNodeFilter(nodeFilter);
            spider.addWatcher(watcher);
            try {
                spider.processUrl(host);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
}
